package gameObjects;

import editor.Grid;
import gameObjects.Material;
import gameObjects.TextureMapping;
import gameObjects.Vector3fCoords;

import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.shape.Box;

public class BuildWalls {
	private static BuildWalls 	buildWalls;
	private Vector3fCoords 		walls3D;
	private Node				wallNode;
	
	
	public static BuildWalls getInstance()
	{
		if(buildWalls==null)
			buildWalls=new BuildWalls();
		return buildWalls;
	}
	
	public Node create()
    {
    	walls3D 		= new Vector3fCoords();
    	walls3D 		= Grid.walls3D;
    	wallNode    	= new Node();
    	Box  wall 		= new Box("WALL");
    	
    	for(int i=0;i<walls3D.getSize();i++)
    	{
    		System.out.println("BUILDING WALL");
    		String wallTexturePath;
    		wallTexturePath = "textures/wall_" + ((int)(Math.random()*3)+1) + ".png";
    		System.out.println("Texture path wall: " + wallTexturePath);
    		wall = new Box("WALL", walls3D.getStartPoint(i), walls3D.getEndPoint(i));
    		Material mat = new Material();
    		wall.setRenderState(mat.getMaterial());
    		TextureMapping tex = new TextureMapping();
    		tex.setTexture(wallTexturePath);
	    	tex.setTextureManager(wall);
	    	wall.setCullHint(CullHint.Never);
	    	wall.setLightCombineMode(LightCombineMode.Replace);
	    	wall.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
	    	wall.setZOrder(0);
	    	wall.updateRenderState();
	    	wallNode.attachChild(wall);
    	}
    	wallNode.updateRenderState();
    	return wallNode;
    }
}
